home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 433_01 / svgadem1.c < prev    next >
C/C++ Source or Header  |  1994-05-08  |  26KB  |  1,168 lines

  1. /****************************************************************************
  2.      
  3.       'SVGACC' A Super Vga Graphics Library for use with Microsoft and
  4.       Borland C/C++
  5.       Copyright 1993-1994 by Stephen L. Balkum and Daniel A. Sill
  6.  
  7.       GIF and 'Graphics Intechange Format' are trademarks (tm) of
  8.       Compuserve, Incorporated, an H&R Block Company.
  9.  
  10.     **************** UNREGISTERD SHAREWARE VERSION ***********************
  11.     * FOR EVUALATION ONLY. NOT FOR RESALE IN ANY FORM. SOFTWARE WRITTEN  *
  12.     * USING THIS UNREGISTERED SHAREWARE GRAPHICS LIBRARY MAY NOT BY SOLD *
  13.     * OR USED FOR ANY PURPOSE OTHER THAN THE EVUALTION OF THIS LIBRARY.  *
  14.     **********************************************************************
  15.  
  16.     **************** NO WARRANTIES AND NO LIABILITY **********************
  17.     * Stephen L. Balkum and Daniel A. Sill provide no warranties, either *
  18.     * expressed or implied, of merchantability, or fitness, for a        *
  19.     * particular use or purpose of this SOFTWARE and documentation.      *
  20.     * In no event shall Stephen L. Balkum or Daniel A. Sill be held      *
  21.     * liable for any damages resulting from the use or misuse of the     * 
  22.     * SOFTWARE and documentation.                                        *
  23.     **********************************************************************
  24.  
  25.     ************** U.S. GOVERNMENT RESTRICTED RIGHTS *********************
  26.     * Use, duplication, or disclosure of the SOFTWARE and documentation  *
  27.     * by the U.S. Government is subject to the restictions as set forth  *
  28.     * in subparagraph (c)(1)(ii) of the Rights in Technical Data and     *
  29.     * Computer Software cluse at DFARS 252.227-7013.                     *
  30.     * Contractor/manufacturer is Stephen L. Balkum and Daniel A. Sill,   *
  31.     * P.O. Box 7704, Austin, Texas 78713-7704                            *
  32.     **********************************************************************
  33.  
  34.     **********************************************************************
  35.     * By using this SOFTWARE or documentation, you agree to the above    *
  36.     * terms and conditions.                                              *
  37.     **********************************************************************
  38.  
  39.  ***************************************************************************/
  40.  
  41. #define MODULE
  42.  
  43. #include <stdio.h>
  44. #include <conio.h>
  45. #include <stdlib.h>
  46. #include <malloc.h>
  47. #include <string.h>
  48. #include <math.h>
  49.  
  50. #include "svgacc.h"
  51.  
  52. #include "svgademo.h"
  53.  
  54. #define randnum(size) (rand() % (int)(size))
  55.  
  56. /***********
  57.  * DOBLOCK *
  58.  ***********/
  59.  
  60. char doblock(void)
  61. {
  62.     int i, colr;
  63.     int xinc, yinc, x1, y1, x2, y2;
  64.     int cntx, cnty;
  65.     char ret;
  66.     char title[TITLEN];
  67.     char buf[TITLEN];
  68.     RasterBlock far *gfxblk;
  69.     RasterBlock far *gfxblk2;
  70.     RasterBlock far *spritebkgnd;
  71.  
  72.     /*
  73.      * Set up the Title
  74.      */
  75.     sprintf(title,"DEMO 5: Block function and Sprites");
  76.     palset(pal,0,255);
  77.  
  78.     /*
  79.      * Show Block Get (draw some circles and "get a chunk of them")
  80.      */
  81.  
  82.     fillscreen(0);
  83.     setview(0,0,maxx,maxy);
  84.     drwstring(1,7,0,title,10,0);
  85.     sprintf(buf,"blkget(x1,y1,x2,y2,GfxBlock);");
  86.     drwstring(1,7,0,buf,10,16);
  87.     colr = 16;
  88.     for(i=0;i<=maxx/2;i++) {
  89.         drwcircle(1,colr,maxx/4+i,maxy/2,maxy/5);
  90.         colr+=2;
  91.         if(colr>255)
  92.             colr = 16;
  93.     }
  94.     
  95.     xinc = maxx/20;
  96.     yinc = maxy/20;
  97.     x1 = maxx/2-xinc;
  98.     y1 = maxy/2-yinc;
  99.     x2 = maxx/2+xinc;
  100.     y2 = maxy/2+yinc;
  101.     i = (x2-x1+1)*(y2-y1+1)+4;
  102.     gfxblk = _fmalloc(i);
  103.     if (!gfxblk) {
  104.         restext();
  105.         printf("ERROR: Allocating memory for gfxblk: %d bytes\n",i);
  106.         exit(1);
  107.     }
  108.     drwbox(1,0,x1,y1,x2,y2);
  109.     blkget(x1,y1,x2,y2,gfxblk);
  110.     
  111.     ret = getkey();
  112.     if ((ret == 's') || (ret == 'q')) {
  113.         fillscreen(0);
  114.         _ffree(gfxblk);
  115.         return(ret);
  116.     }
  117.  
  118.     /*
  119.      * Show Block Rotate and Sprite Stuff
  120.      */
  121.     drwstring(1,7,0,title,10,0);
  122.     sprintf(buf,"blkrotate(angle,backfill,GfxBlockSrc,GfxBlockDst);");
  123.     drwstring(1,7,0,buf,10,16);
  124.     sprintf(buf,"spritegap(transcolor,x,y,SpriteArray,BkGndArray);");
  125.     drwstring(1,7,0,buf,10,32);
  126.     sprintf(buf,"spriteput(transcolor,x,y,SpriteArray);");
  127.     drwstring(1,7,0,buf,10,48);
  128.     cntx = (x2-x1) / 2 + x1;
  129.     cnty = (y2-y1) / 2 + y1;
  130.     fillarea(x1+2,y1+2,0,0);
  131.     i = blkrotatesize(45,gfxblk);
  132.     spritebkgnd = _fmalloc(i);
  133.     if (!spritebkgnd) {
  134.         restext();
  135.         printf("ERROR: Allocating memory for spritebkgnd: %d bytes\n",i);
  136.         exit(1);
  137.     }
  138.     gfxblk2 = _fmalloc(i);
  139.     if (!gfxblk2) {
  140.         restext();
  141.         printf("ERROR: Allocating memory for gfxblk2: %d bytes\n",i);
  142.         exit(1);
  143.     }
  144.     blkget(x1,y1,x2,y2,spritebkgnd);
  145.     setview(0,64,maxx,maxy);
  146.  
  147.     for(i=0;i<=360;i+=4) {
  148.         blkrotate(i,1,gfxblk,gfxblk2);
  149.         spriteput(SET,1,cntx-(spritebkgnd->width)/2,cnty-(spritebkgnd->height)/2,spritebkgnd);
  150.         spritegap(1,cntx-(gfxblk2->width)/2,cnty-(gfxblk2->height)/2,gfxblk2,spritebkgnd);
  151.         sdelay(4);
  152.     }
  153.     spriteput(SET,1,cntx-(spritebkgnd->width)/2,cnty-(spritebkgnd->height)/2,spritebkgnd);
  154.     blkput(SET,x1,y1,gfxblk);
  155.  
  156.     setview(0,0,maxx,maxy);
  157.     ret = getkey();
  158.     if ((ret == 's') || (ret == 'q')) {
  159.         fillscreen(0);
  160.         palset(pal,16,255);
  161.         _ffree(gfxblk);
  162.         _ffree(gfxblk2);
  163.         _ffree(spritebkgnd);
  164.         return(ret);
  165.     }
  166.  
  167.     /*
  168.      * Show Block Resize and Sprite Stuff
  169.      */
  170.     drwstring(1,7,0,title,10,0);
  171.     sprintf(buf,"blkresize(Width,Height,GfxBlockSrc,GfxBlockDst);");
  172.     drwstring(1,7,0,buf,10,16);
  173.     sprintf(buf,"spritegap(transcolor,x,y,SpriteArray,BkGndArray);");
  174.     drwstring(1,7,0,buf,10,32);
  175.     sprintf(buf,"spriteput(transcolor,x,y,SpriteArray);");
  176.     drwstring(1,7,0,buf,10,48);
  177.     fillarea(x1+2,y1+2,0,0);
  178.     blkget(x1,y1,x2,y2,spritebkgnd);
  179.     setview(0,64,maxx,maxy);
  180.  
  181.     i = (x2-x1+1+xinc)*(y2-y1+1+xinc)+4;
  182.  
  183.     spritebkgnd = _frealloc(spritebkgnd,i);
  184.     if (!spritebkgnd) {
  185.         restext();
  186.         printf("ERROR: reallocating memory for spritebkgnd: %d bytes\n",i);
  187.         exit(1);
  188.     }
  189.  
  190.     gfxblk2 = _frealloc(gfxblk2,i);
  191.     if (!gfxblk2) {
  192.         restext();
  193.         printf("ERROR: reallocating memory for gfxblk2: %d bytes\n",i);
  194.         exit(1);
  195.     }
  196.  
  197.     for(i=0;i<=xinc;i++) {
  198.         blkresize((gfxblk->width)-i,(gfxblk->height)-i,gfxblk,gfxblk2);
  199.         spriteput(SET,1,cntx-(spritebkgnd->width)/2,cnty-(spritebkgnd->height)/2,spritebkgnd);
  200.         spritegap(1,cntx-(gfxblk2->width)/2,cnty-(gfxblk2->height)/2,gfxblk2,spritebkgnd);
  201.         sdelay(3);
  202.     }
  203.     spriteput(SET,1,cntx-(spritebkgnd->width)/2,cnty-(spritebkgnd->height)/2,spritebkgnd);
  204.  
  205.     for(i=xinc;i>=0;i--) {
  206.         blkresize((gfxblk->width)-i,(gfxblk->height)-i,gfxblk,gfxblk2);
  207.         spriteput(SET,1,cntx-(spritebkgnd->width)/2,cnty-(spritebkgnd->height)/2,spritebkgnd);
  208.         spritegap(1,cntx-(gfxblk2->width)/2,cnty-(gfxblk2->height)/2,gfxblk2,spritebkgnd);
  209.         sdelay(3);
  210.     }
  211.     spriteput(SET,1,cntx-(spritebkgnd->width)/2,cnty-(spritebkgnd->height)/2,spritebkgnd);
  212.     blkput(SET,x1,y1,gfxblk);
  213.  
  214.     ret = getkey();
  215.     if ((ret == 's') || (ret == 'q')) {
  216.         fillscreen(0);
  217.         palset(pal,16,255);
  218.         setview(0,0,maxx,maxy);
  219.         _ffree(gfxblk);
  220.         _ffree(gfxblk2);
  221.         _ffree(spritebkgnd);
  222.         return(ret);
  223.     }
  224.  
  225.  
  226.     /*
  227.      * Show Block Put (put the "chunks" randomly around the screen)
  228.      */
  229.     setview(0,16,maxx,32);
  230.     fillview(0);
  231.     sprintf(buf,"blkput(mode,x,y,GfxBlock);");
  232.     drwstring(1,7,0,buf,10,16);
  233.     xinc = maxx/10;
  234.     yinc = maxy/10;
  235.     setview(0,32,maxx,maxy);
  236.     for(i=0;i<=maxx/2;i++) {
  237.         x1 = randnum(maxx + xinc) - xinc;
  238.         y1 = randnum(maxy + yinc) - yinc;
  239.         blkput(1,x1,y1,gfxblk);
  240.     }
  241.  
  242.     _ffree(gfxblk);
  243.     _ffree(gfxblk2);
  244.     _ffree(spritebkgnd);
  245.     setview(0,0,maxx,maxy);
  246.     ret = getkey();
  247.     if ((ret == 's') || (ret == 'q')) {
  248.         fillscreen(0);
  249.         return(ret);
  250.     }
  251.  
  252.     return(ret);
  253.     
  254. }
  255.  
  256.  
  257.  
  258. /**********
  259.  * DOCLIP *
  260.  **********/
  261.  
  262. char doclip(void)
  263. {
  264.     struct dcoord {
  265.         int x1;
  266.         int x2;
  267.         int y1;
  268.         int y2;
  269.     };
  270.     
  271.     int i, j, k;
  272.     int xinc, x, y, x1, y1, x2, y2;
  273.     int xsub, radx, rady;
  274.     int wdth, hgth, spcingx, spcingy;
  275.     struct dcoord b[4];
  276.     char ret;
  277.     char title[TITLEN];
  278.     char buf[TITLEN];
  279.     
  280.     /*
  281.      * Set up the Title
  282.      */
  283.     sprintf(title,"DEMO 2: Clipping capability");
  284.     palset(pal,0,255);
  285.  
  286.     /*
  287.      * Set up the windows
  288.      */
  289.  
  290.     fillscreen(0);
  291.     setview(0,0,maxx,maxy);
  292.     drwstring(1,7,0,title,10,0);
  293.     sprintf(buf,"All pimitives automatically clip");
  294.     drwstring(1,7,0,buf,10,16);
  295.  
  296.     wdth = (maxx + 1) * 4 / 9;
  297.     spcingx =